/*
 * @(#) UserInputForm.java      27/03/07
 *
 * Copyright 2007 JUBCSE-II. All rights reserved
 * JUBCSE-II GR-2 PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package busticketvendingsystem;

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.text.SimpleDateFormat;
import busticketvendingsystem.*;

/**
 * Extended form <code>javax.swing.JFrame</code> this class creates the main
 * GUI of the project. It creates the main form for passengers to fill up
 * in order to get bus tickets.
 * For testing purposes this class is made executable by including a main 
 * method in the class.
 * This class declares the components of the GUI form as its instance
 * variables.
 * The constructor <code>public UserInputForm()</code> has no parameters.
 * It calls only one method <code>initComponents</code>
 * The <code>private</code> method <code>initComponents</code> actually 
 * creates the GUI.
 * Other <code>private</code> methods in this class are called from within 
 * the Listeners classes.
 *
 * @version 1.001 27/03/2007
 * @author Samik Saha
 * @author Somenath Kundu
 */
public class UserInputForm extends javax.swing.JFrame {
    private static UserData userData;
    SpinnerModel noTicketsModel;
    ConnectDatabase cd=new ConnectDatabase();
    boolean type=true;
    /** Creates new form UserInputForm */
    public UserInputForm() {
        userData=new UserData();
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        ticketTypeButtonGroup = new javax.swing.ButtonGroup();
        concessionTypeButtonGroup = new javax.swing.ButtonGroup();
        upDownButtonGroup = new javax.swing.ButtonGroup();
        tabbedPane = new javax.swing.JTabbedPane();
        ticketTransaction = new javax.swing.JPanel();
        footerPanel = new javax.swing.JPanel();
        aboutButton = new javax.swing.JButton();
        resetAllButton = new javax.swing.JButton();
        submitButton2 = new javax.swing.JButton();
        headerPanel = new javax.swing.JPanel();
        dateTimeLabel = new javax.swing.JLabel();
        helpButton = new javax.swing.JButton();
        mapButton = new javax.swing.JButton();
        fillInLabel = new javax.swing.JLabel();
        informationPane = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        mainPane = new javax.swing.JScrollPane();
        inputFormPanel = new javax.swing.JPanel();
        ticketTypePanel = new javax.swing.JPanel();
        regularRadioButton = new javax.swing.JRadioButton();
        monthlyRadioButton = new javax.swing.JRadioButton();
        quarterlyRadioButton = new javax.swing.JRadioButton();
        yearlyRadioButton = new javax.swing.JRadioButton();
        concessionPanel = new javax.swing.JPanel();
        concessionCB = new javax.swing.JCheckBox();
        studentRB = new javax.swing.JRadioButton();
        pdRB = new javax.swing.JRadioButton();
        seniorRB = new javax.swing.JRadioButton();
        concessionIllustration = new javax.swing.JLabel();
        bottomPanel = new javax.swing.JPanel();
        stoppagePanel = new javax.swing.JPanel();
        startingPointLabel = new javax.swing.JLabel();
        startingPointCB = new javax.swing.JComboBox();
        destinationLabel = new javax.swing.JLabel();
        destinationCB = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        schedulePanel = new javax.swing.JPanel();
        scheduleTimeLabel = new javax.swing.JLabel();
        scheduleTimeCB = new javax.swing.JComboBox();
        busNoLabel = new javax.swing.JLabel();
        busNoTextField = new javax.swing.JTextField();
        noOfSeatsLabel = new javax.swing.JLabel();
        noOfSeatsTextField = new javax.swing.JTextField();
        topPanel = new javax.swing.JPanel();
        upDownPanel = new javax.swing.JPanel();
        upRB = new javax.swing.JRadioButton();
        downRB = new javax.swing.JRadioButton();
        noTicketsPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        noTicketsSpinner = new javax.swing.JSpinner();
        administrativeUse = new javax.swing.JPanel();
        helpButton3 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        enterPasswordLabel = new javax.swing.JLabel();
        enterPasswordField = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPasswordField2 = new javax.swing.JPasswordField();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPasswordField3 = new javax.swing.JPasswordField();
        jPasswordField4 = new javax.swing.JPasswordField();
        save = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Bus Ticket Vending System");
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setIconImage(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/bus50x50.gif")).getImage());
        setUndecorated(true);
        tabbedPane.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        ticketTransaction.setLayout(new java.awt.BorderLayout());

        ticketTransaction.setBackground(new java.awt.Color(245, 252, 255));
        ticketTransaction.setToolTipText("Click for ticket transaction");
        footerPanel.setBackground(new java.awt.Color(204, 255, 204));
        aboutButton.setText("About...");
        aboutButton.setToolTipText("About this software");
        aboutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutButtonActionPerformed(evt);
            }
        });

        resetAllButton.setText("Reset All");
        resetAllButton.setToolTipText("Reset all fields to its default value");
        resetAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetAllButtonActionPerformed(evt);
            }
        });

        submitButton2.setText("Submit...");
        submitButton2.setToolTipText("Submit the information supplied above");
        submitButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout footerPanelLayout = new org.jdesktop.layout.GroupLayout(footerPanel);
        footerPanel.setLayout(footerPanelLayout);
        footerPanelLayout.setHorizontalGroup(
            footerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(footerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(aboutButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(resetAllButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 240, Short.MAX_VALUE)
                .add(submitButton2)
                .addContainerGap())
        );
        footerPanelLayout.setVerticalGroup(
            footerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, footerPanelLayout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(footerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(aboutButton)
                    .add(resetAllButton)
                    .add(submitButton2))
                .addContainerGap())
        );
        ticketTransaction.add(footerPanel, java.awt.BorderLayout.SOUTH);

        dateTimeLabel.setFont(new java.awt.Font("Arial", 1, 14));
        dateTimeLabel.setForeground(new java.awt.Color(204, 102, 0));
        dateTimeLabel.setText("current date and time");
        dateTimeLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        DateTimeThread dateTimeThread=new DateTimeThread(dateTimeLabel);
        dateTimeThread.start();

        helpButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/help_icon.gif")));
        helpButton.setToolTipText("Click to get help");
        helpButton.setOpaque(false);
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        mapButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/mapicon.gif")));
        mapButton.setToolTipText("Click to view map");
        mapButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mapButtonActionPerformed(evt);
            }
        });

        fillInLabel.setText("Please fill in the following form:");

        org.jdesktop.layout.GroupLayout headerPanelLayout = new org.jdesktop.layout.GroupLayout(headerPanel);
        headerPanel.setLayout(headerPanelLayout);
        headerPanelLayout.setHorizontalGroup(
            headerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(headerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(headerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(dateTimeLabel)
                    .add(fillInLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 148, Short.MAX_VALUE)
                .add(mapButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(helpButton)
                .addContainerGap())
        );
        headerPanelLayout.setVerticalGroup(
            headerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(headerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(headerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(headerPanelLayout.createSequentialGroup()
                        .add(dateTimeLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(fillInLabel))
                    .add(mapButton)
                    .add(helpButton))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        ticketTransaction.add(headerPanel, java.awt.BorderLayout.NORTH);

        informationPane.setPreferredSize(new java.awt.Dimension(300, 44));
        jEditorPane1.setEditable(false);
        try {
            jEditorPane1.setPage(getClass().getResource("/busticketvendingsystem/resources/html/imp_information.htm"));
        } catch (java.io.IOException e1) {
            e1.printStackTrace();
        }
        informationPane.setViewportView(jEditorPane1);

        ticketTransaction.add(informationPane, java.awt.BorderLayout.EAST);

        mainPane.setPreferredSize(new java.awt.Dimension(600, 12));
        inputFormPanel.setLayout(new java.awt.BorderLayout());

        inputFormPanel.setPreferredSize(new java.awt.Dimension(470, 500));
        ticketTypePanel.setLayout(new javax.swing.BoxLayout(ticketTypePanel, javax.swing.BoxLayout.Y_AXIS));

        ticketTypePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Select Ticket Type", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11)));
        ticketTypePanel.setPreferredSize(new java.awt.Dimension(200, 202));
        ticketTypePanel.add(Box.createRigidArea(new Dimension(0,5)));
        ticketTypeButtonGroup.add(regularRadioButton);
        regularRadioButton.setSelected(true);
        regularRadioButton.setText("<html><b>Regular</b><br/>You will be able make only one trip from starting point to destination.<br/>Ticket will be valid only for today</html>");
        regularRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        regularRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        regularRadioButton.setOpaque(false);
        regularRadioButton.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        regularRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                regularRadioButtonItemStateChanged(evt);
            }
        });

        ticketTypePanel.add(regularRadioButton);

        ticketTypePanel.add(Box.createRigidArea(new Dimension(0,5)));
        ticketTypeButtonGroup.add(monthlyRadioButton);
        monthlyRadioButton.setText("<html><b>Monthly</b><br/>You will be able to travel both up and down any number of times in one month.<br/>Ticket is valid for one month.</html> ");
        monthlyRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        monthlyRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        monthlyRadioButton.setOpaque(false);
        monthlyRadioButton.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        monthlyRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                monthlyRadioButtonItemStateChanged(evt);
            }
        });

        ticketTypePanel.add(monthlyRadioButton);

        ticketTypePanel.add(Box.createRigidArea(new Dimension(0,5)));
        ticketTypeButtonGroup.add(quarterlyRadioButton);
        quarterlyRadioButton.setText("<html><b>Quarterly</b><br/>You will be able travel both up and down any number of times in three months.<br/>Ticket is valid for three months starting today.</html>");
        quarterlyRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        quarterlyRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        quarterlyRadioButton.setOpaque(false);
        quarterlyRadioButton.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        quarterlyRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                quarterlyRadioButtonItemStateChanged(evt);
            }
        });

        ticketTypePanel.add(quarterlyRadioButton);

        ticketTypePanel.add(Box.createRigidArea(new Dimension(0,5)));
        ticketTypeButtonGroup.add(yearlyRadioButton);
        yearlyRadioButton.setText("<html><b>Yearly</b><br/>You will be able travel both up and down any number of times in one year.<br/>Ticket will be valid for one year starting today.</html>");
        yearlyRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        yearlyRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        yearlyRadioButton.setOpaque(false);
        yearlyRadioButton.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        yearlyRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                yearlyRadioButtonItemStateChanged(evt);
            }
        });

        ticketTypePanel.add(yearlyRadioButton);

        inputFormPanel.add(ticketTypePanel, java.awt.BorderLayout.CENTER);

        concessionPanel.setLayout(new javax.swing.BoxLayout(concessionPanel, javax.swing.BoxLayout.Y_AXIS));

        concessionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Concession", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11)));
        concessionPanel.setOpaque(false);
        concessionPanel.setPreferredSize(new java.awt.Dimension(200, 104));
        concessionPanel.add(Box.createRigidArea(new Dimension(0,5)));
        concessionCB.setText("Concession");
        concessionCB.setAlignmentX(0.5F);
        concessionCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        concessionCB.setMargin(new java.awt.Insets(0, 0, 0, 0));
        concessionCB.setOpaque(false);
        concessionCB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                concessionCBItemStateChanged(evt);
            }
        });

        concessionPanel.add(concessionCB);

        concessionPanel.add(Box.createRigidArea(new Dimension(0,10)));
        concessionTypeButtonGroup.add(studentRB);
        studentRB.setSelected(true);
        studentRB.setText("<html><b>Student</b><br/>Applies to school/college going students whose institution falls on this route</html>");
        studentRB.setActionCommand("student");
        studentRB.setAlignmentX(0.5F);
        studentRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        studentRB.setEnabled(false);
        studentRB.setMargin(new java.awt.Insets(0, 0, 0, 0));
        studentRB.setOpaque(false);
        studentRB.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        studentRB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                studentRBItemStateChanged(evt);
            }
        });

        concessionPanel.add(studentRB);

        concessionPanel.add(Box.createRigidArea(new Dimension(0,5)));
        concessionTypeButtonGroup.add(pdRB);
        pdRB.setText("<html><b>Physically Disabled</b><br/>Applies to people with physical disablities. </html>");
        pdRB.setActionCommand("pd");
        pdRB.setAlignmentX(0.5F);
        pdRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        pdRB.setEnabled(false);
        pdRB.setMargin(new java.awt.Insets(0, 0, 0, 0));
        pdRB.setOpaque(false);
        pdRB.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        pdRB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                pdRBItemStateChanged(evt);
            }
        });

        concessionPanel.add(pdRB);

        concessionPanel.add(Box.createRigidArea(new Dimension(0,5)));
        concessionTypeButtonGroup.add(seniorRB);
        seniorRB.setText("<html><b>Senior Citizen</b><br/>Applies to senior citizens</html>");
        seniorRB.setActionCommand("senior_citizen");
        seniorRB.setAlignmentX(0.5F);
        seniorRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        seniorRB.setEnabled(false);
        seniorRB.setMargin(new java.awt.Insets(0, 0, 0, 0));
        seniorRB.setOpaque(false);
        seniorRB.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        seniorRB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                seniorRBItemStateChanged(evt);
            }
        });

        concessionPanel.add(seniorRB);

        concessionPanel.add(Box.createRigidArea(new Dimension(0,10)));
        concessionIllustration.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/student.gif")));
        concessionIllustration.setAlignmentX(0.5F);
        concessionPanel.add(concessionIllustration);

        inputFormPanel.add(concessionPanel, java.awt.BorderLayout.EAST);

        bottomPanel.setLayout(new javax.swing.BoxLayout(bottomPanel, javax.swing.BoxLayout.X_AXIS));

        stoppagePanel.setLayout(new java.awt.GridLayout(3, 0));

        stoppagePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Select starting and destination stoppages", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11)));
        startingPointLabel.setText("Starting point");
        stoppagePanel.add(startingPointLabel);

        startingPointCB.setModel(new javax.swing.DefaultComboBoxModel(cd.getStoppage_name()));
        startingPointCB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                startingPointCBItemStateChanged(evt);
            }
        });

        stoppagePanel.add(startingPointCB);

        destinationLabel.setText("Destination");
        stoppagePanel.add(destinationLabel);

        destinationCB.setModel(new javax.swing.DefaultComboBoxModel(cd.getStoppage_name_back()));
        destinationCB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                destinationCBItemStateChanged(evt);
            }
        });

        stoppagePanel.add(destinationCB);

        jLabel1.setText("Distance =");
        stoppagePanel.add(jLabel1);

        jTextField1.setEditable(false);
        jTextField1.setText(""+cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
        stoppagePanel.add(jTextField1);

        bottomPanel.add(stoppagePanel);

        schedulePanel.setLayout(new java.awt.GridLayout(3, 0));

        schedulePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Specify time", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11)));
        scheduleTimeLabel.setText("Schedule time");
        schedulePanel.add(scheduleTimeLabel);

        scheduleTimeCB.setModel(new javax.swing.DefaultComboBoxModel(getScheduleTime(1)));
        scheduleTimeCB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                scheduleTimeCBItemStateChanged(evt);
            }
        });

        schedulePanel.add(scheduleTimeCB);

        busNoLabel.setText("Bus no.");
        schedulePanel.add(busNoLabel);

        busNoTextField.setEditable(false);
        busNoTextField.setText(""+cd.getBus_numberbyUp((String)scheduleTimeCB.getSelectedItem()));
        schedulePanel.add(busNoTextField);

        noOfSeatsLabel.setText("No. of seats available");
        schedulePanel.add(noOfSeatsLabel);

        noOfSeatsTextField.setEditable(false);
        noOfSeatsTextField.setText(""+getAvailable_seats(busNoTextField.getText(),(String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
        schedulePanel.add(noOfSeatsTextField);

        bottomPanel.add(schedulePanel);

        inputFormPanel.add(bottomPanel, java.awt.BorderLayout.SOUTH);

        topPanel.setLayout(new javax.swing.BoxLayout(topPanel, javax.swing.BoxLayout.X_AXIS));

        upDownButtonGroup.add(upRB);
        upRB.setSelected(true);
        upRB.setText("Up");
        upRB.setToolTipText("Garia -> Howrah");
        upRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        upRB.setMargin(new java.awt.Insets(0, 0, 0, 0));
        upRB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                upRBItemStateChanged(evt);
            }
        });

        upDownPanel.add(upRB);

        upDownButtonGroup.add(downRB);
        downRB.setText("Down");
        downRB.setToolTipText("Howrah -> Garia");
        downRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        downRB.setMargin(new java.awt.Insets(0, 0, 0, 0));
        downRB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                downRBItemStateChanged(evt);
            }
        });

        upDownPanel.add(downRB);

        topPanel.add(upDownPanel);

        jLabel2.setText("Number of tickets:");
        noTicketsPanel.add(jLabel2);

        noTicketsModel=new SpinnerNumberModel(1,1,50,1);
        noTicketsSpinner.setModel(noTicketsModel);
        noTicketsPanel.add(noTicketsSpinner);

        topPanel.add(noTicketsPanel);

        inputFormPanel.add(topPanel, java.awt.BorderLayout.NORTH);

        mainPane.setViewportView(inputFormPanel);

        ticketTransaction.add(mainPane, java.awt.BorderLayout.CENTER);

        tabbedPane.addTab("Ticket Transaction", ticketTransaction);

        administrativeUse.setBackground(new java.awt.Color(251, 242, 242));
        administrativeUse.setToolTipText("Click for administrative use");
        helpButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/help_icon.gif")));
        helpButton3.setOpaque(false);
        helpButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButton3ActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel6.setForeground(new java.awt.Color(51, 0, 0));
        jLabel6.setText("For administrative use only");

        enterPasswordLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/password.gif")));
        enterPasswordLabel.setText("Enter password:");

        enterPasswordField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enterPasswordFieldActionPerformed(evt);
            }
        });

        jButton1.setText("Log in");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Forgot my password");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel3.setText("Create new password or change existing password:");

        jLabel4.setText("Current password:");

        jLabel5.setText("(leave blank if you do not have any password)");

        jLabel7.setText("New passowrd:");

        jLabel8.setText("Re-enter new password:");

        jPasswordField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPasswordField4ActionPerformed(evt);
            }
        });

        save.setText("Save");
        save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/close.gif")));
        jButton4.setText("Quit BusTicketVendingSystem");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout administrativeUseLayout = new org.jdesktop.layout.GroupLayout(administrativeUse);
        administrativeUse.setLayout(administrativeUseLayout);
        administrativeUseLayout.setHorizontalGroup(
            administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(administrativeUseLayout.createSequentialGroup()
                .addContainerGap()
                .add(administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel4)
                    .add(jLabel7)
                    .add(jLabel8))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jPasswordField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                    .add(jPasswordField3)
                    .add(jPasswordField4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel5)
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, administrativeUseLayout.createSequentialGroup()
                .addContainerGap(288, Short.MAX_VALUE)
                .add(jButton4)
                .add(10, 10, 10))
            .add(administrativeUseLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(save)
                .addContainerGap(424, Short.MAX_VALUE))
            .add(administrativeUseLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jLabel3)
                .addContainerGap(232, Short.MAX_VALUE))
            .add(administrativeUseLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                .addContainerGap(16, Short.MAX_VALUE))
            .add(administrativeUseLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jButton2)
                .addContainerGap(350, Short.MAX_VALUE))
            .add(administrativeUseLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(enterPasswordLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(enterPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 115, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1)
                .addContainerGap(181, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, administrativeUseLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel6)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 176, Short.MAX_VALUE)
                .add(helpButton3)
                .add(10, 10, 10))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, administrativeUseLayout.createSequentialGroup()
                .addContainerGap()
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE)
                .addContainerGap())
        );
        administrativeUseLayout.setVerticalGroup(
            administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(administrativeUseLayout.createSequentialGroup()
                .addContainerGap()
                .add(administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(helpButton3)
                    .add(jLabel6))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(enterPasswordLabel)
                    .add(jButton1)
                    .add(enterPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(jLabel5)
                    .add(jPasswordField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(jPasswordField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(administrativeUseLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel8)
                    .add(jPasswordField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(save)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 18, Short.MAX_VALUE)
                .add(jButton4)
                .addContainerGap())
        );
        tabbedPane.addTab("Administrative Use", administrativeUse);

        getContentPane().add(tabbedPane, java.awt.BorderLayout.CENTER);

        jPanel1.setBackground(new java.awt.Color(204, 255, 204));
        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel9.setForeground(new java.awt.Color(102, 102, 0));
        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/bus50x50.gif")));
        jLabel9.setText("Bus Ticket Vending System");

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel10.setForeground(new java.awt.Color(102, 102, 0));
        jLabel10.setText("Get tickets in seconds");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel9))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(202, 202, 202)
                        .add(jLabel10)))
                .addContainerGap(267, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jLabel9)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel10)
                .addContainerGap(22, Short.MAX_VALUE))
        );
        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        JOptionPane.showMessageDialog(null,"Contact the Developer!","Information",JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void helpButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButton3ActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HelpWindow(UserInputForm.this,true).setVisible(true);
            }
        });
    }//GEN-LAST:event_helpButton3ActionPerformed

    private void jPasswordField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField4ActionPerformed
        setPassword();
    }//GEN-LAST:event_jPasswordField4ActionPerformed

    private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed
        setPassword();
    }//GEN-LAST:event_saveActionPerformed

    private void scheduleTimeCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_scheduleTimeCBItemStateChanged
// TODO add your handling code here:
        userData.setScheduleTime((String)scheduleTimeCB.getSelectedItem());
        String sname1=(String)startingPointCB.getSelectedItem();
        String sname2=(String)destinationCB.getSelectedItem();
        String bnumber=busNoTextField.getText();
        noOfSeatsTextField.setText(""+getAvailable_seats(bnumber,sname1,sname2));
        if(upRB.isSelected()){
            busNoTextField.setText(cd.getBus_numberbyUp((String)scheduleTimeCB.getSelectedItem()));
            userData.setBusNo(busNoTextField.getText());
        }
        else{
            busNoTextField.setText(cd.getBus_numberbyDown((String)scheduleTimeCB.getSelectedItem()));
            userData.setBusNo(busNoTextField.getText());
        }
    }//GEN-LAST:event_scheduleTimeCBItemStateChanged

    private void destinationCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_destinationCBItemStateChanged
        jTextField1.setText(""+cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
        userData.setDestination((String)destinationCB.getSelectedItem());
        userData.setDistance(cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
        String sname1=(String)startingPointCB.getSelectedItem();
        String sname2=(String)destinationCB.getSelectedItem();
        String bnumber=busNoTextField.getText();
        noOfSeatsTextField.setText(""+getAvailable_seats(bnumber,sname1,sname2));
        if(cd.getDistance((String)startingPointCB.getSelectedItem())<cd.getDistance((String)destinationCB.getSelectedItem())){
            type=false;
            upRB.setSelected(true);
            type=true;
        }
        else if(cd.getDistance((String)startingPointCB.getSelectedItem())>cd.getDistance((String)destinationCB.getSelectedItem())){
            type=false;
            downRB.setSelected(true);
            type=true;
        }
    }//GEN-LAST:event_destinationCBItemStateChanged

    private void startingPointCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_startingPointCBItemStateChanged
        jTextField1.setText(""+cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
        userData.setStartingStop((String)startingPointCB.getSelectedItem());
        userData.setDistance(cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
        String sname1=(String)startingPointCB.getSelectedItem();
        String sname2=(String)destinationCB.getSelectedItem();
        String bnumber=busNoTextField.getText();
        noOfSeatsTextField.setText(""+getAvailable_seats(bnumber,sname1,sname2));
        if(cd.getDistance((String)startingPointCB.getSelectedItem())<cd.getDistance((String)destinationCB.getSelectedItem())){
            type=false;
            upRB.setSelected(true);
            type=true;
        }
        else if(cd.getDistance((String)startingPointCB.getSelectedItem())>cd.getDistance((String)destinationCB.getSelectedItem())){
            type=false;
            downRB.setSelected(true);
            type=true;
        }
        
    }//GEN-LAST:event_startingPointCBItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        logIn();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void enterPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enterPasswordFieldActionPerformed
        logIn();
    }//GEN-LAST:event_enterPasswordFieldActionPerformed

    private void downRBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_downRBItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED&&type==true){
             userData.setDirection(UserData.DOWN);
             startingPointCB.setModel(new javax.swing.DefaultComboBoxModel(cd.getStoppage_name_back()));
             userData.setStartingStop((String)startingPointCB.getSelectedItem());
             destinationCB.setModel(new javax.swing.DefaultComboBoxModel(cd.getStoppage_name()));
             userData.setDestination((String)destinationCB.getSelectedItem());
             scheduleTimeCB.setModel(new javax.swing.DefaultComboBoxModel(getScheduleTime(0)));
             userData.setScheduleTime((String)scheduleTimeCB.getSelectedItem());
             busNoTextField.setText(cd.getBus_numberbyDown((String)scheduleTimeCB.getSelectedItem()));
             userData.setBusNo(busNoTextField.getText());
             jTextField1.setText(""+cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
             userData.setDistance(cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
             String sname1=(String)startingPointCB.getSelectedItem();
        String sname2=(String)destinationCB.getSelectedItem();
        String bnumber=busNoTextField.getText();
        noOfSeatsTextField.setText(""+getAvailable_seats(bnumber,sname1,sname2));
         }
    }//GEN-LAST:event_downRBItemStateChanged

    private void upRBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_upRBItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED&&type==true){
             userData.setDirection(UserData.UP);
             destinationCB.setModel(new javax.swing.DefaultComboBoxModel(cd.getStoppage_name_back()));
             userData.setDestination((String)destinationCB.getSelectedItem());
             startingPointCB.setModel(new javax.swing.DefaultComboBoxModel(cd.getStoppage_name()));
             userData.setStartingStop((String)startingPointCB.getSelectedItem());
             scheduleTimeCB.setModel(new javax.swing.DefaultComboBoxModel(getScheduleTime(1)));
             userData.setScheduleTime((String)scheduleTimeCB.getSelectedItem());
             busNoTextField.setText(cd.getBus_numberbyUp((String)scheduleTimeCB.getSelectedItem()));
             userData.setBusNo(busNoTextField.getText());
             jTextField1.setText(""+cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
             userData.setDistance(cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem()));
             String sname1=(String)startingPointCB.getSelectedItem();
        String sname2=(String)destinationCB.getSelectedItem();
        String bnumber=busNoTextField.getText();
        noOfSeatsTextField.setText(""+getAvailable_seats(bnumber,sname1,sname2));
         }
    }//GEN-LAST:event_upRBItemStateChanged

    private void yearlyRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_yearlyRadioButtonItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED){
             userData.setTicketType(UserData.YEARLY);
         }
    }//GEN-LAST:event_yearlyRadioButtonItemStateChanged

    private void quarterlyRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_quarterlyRadioButtonItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED){
             userData.setTicketType(UserData.QUARTERLY);
         }
    }//GEN-LAST:event_quarterlyRadioButtonItemStateChanged

    private void monthlyRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_monthlyRadioButtonItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED){
             userData.setTicketType(UserData.MONTHLY);
         }
    }//GEN-LAST:event_monthlyRadioButtonItemStateChanged

    private void regularRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_regularRadioButtonItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED){
             userData.setTicketType(UserData.REGULAR);
         }
    }//GEN-LAST:event_regularRadioButtonItemStateChanged

    private void seniorRBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_seniorRBItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED){
             userData.setConcessionType(UserData.SENIOR_CITIZEN);
             concessionIllustration.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/senior_citizen.gif")));
         }
    }//GEN-LAST:event_seniorRBItemStateChanged

    private void pdRBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_pdRBItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED){
             userData.setConcessionType(UserData.PHYSICALLY_DISABLED);
             //change illustration icon
             concessionIllustration.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/pd.gif")));
         }
    }//GEN-LAST:event_pdRBItemStateChanged

    private void studentRBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_studentRBItemStateChanged
         if(evt.getStateChange()==ItemEvent.SELECTED){
             //change the illustrating image
             concessionIllustration.setIcon(new javax.swing.ImageIcon(getClass().getResource("/busticketvendingsystem/resources/images/student.gif")));
             //change concession type in userData
             userData.setConcessionType(UserData.STUDENT);
         }
    }//GEN-LAST:event_studentRBItemStateChanged

    private void resetAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetAllButtonActionPerformed
        upRB.setSelected(true);
        regularRadioButton.setSelected(true);
        concessionCB.setSelected(false);
        studentRB.setSelected(true);
        startingPointCB.setSelectedIndex(0);
        destinationCB.setSelectedIndex(0);
        scheduleTimeCB.setModel(new javax.swing.DefaultComboBoxModel(getScheduleTime(1)));
        noTicketsSpinner.setValue((Object)1);
        busNoTextField.setText(cd.getBus_numberbyUp((String)scheduleTimeCB.getSelectedItem()));
        String sname1=(String)startingPointCB.getSelectedItem();
        String sname2=(String)destinationCB.getSelectedItem();
        String bnumber=busNoTextField.getText();
        noOfSeatsTextField.setText(""+getAvailable_seats(bnumber,sname1,sname2));
    }//GEN-LAST:event_resetAllButtonActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void mapButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mapButtonActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new busticketvendingsystem.MapDialog(UserInputForm.this,true).setVisible(true);
            }
        });
    }//GEN-LAST:event_mapButtonActionPerformed

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HelpWindow(UserInputForm.this,true).setVisible(true);
            }
        });
    }//GEN-LAST:event_helpButtonActionPerformed

    private void submitButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitButton2ActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                if(cd.getDistance((String)startingPointCB.getSelectedItem())==cd.getDistance((String)destinationCB.getSelectedItem())){
                                             
                    JOptionPane.showMessageDialog(UserInputForm.this,"You can't select same starting and destination stoppage!","ERROR",JOptionPane.ERROR_MESSAGE);
            
                }
                else if(Integer.parseInt(noTicketsSpinner.getValue().toString())>userData.getAvailableSeats()){
                    JOptionPane.showMessageDialog(UserInputForm.this,"Required "+noTicketsSpinner.getValue().toString()+" seats are not available in the Bus having No. "+userData.getBusNo(),"ERROR",JOptionPane.ERROR_MESSAGE);
                }
                else{
                    userData.setNoTickets(Integer.parseInt(noTicketsSpinner.getValue().toString()));    
                    String sname1=(String)startingPointCB.getSelectedItem();
                    String sname2=(String)destinationCB.getSelectedItem();
                    String bnumber=busNoTextField.getText();
                    userData.setAvailableSeats(getAvailable_seats(bnumber,sname1,sname2));
                    userData.setScheduleTime((String)scheduleTimeCB.getSelectedItem());
                    countAmount();
                    new busticketvendingsystem.ConfirmationDialog(UserInputForm.this,true,UserInputForm.userData).setVisible(true);
                }
            }
        });
    }//GEN-LAST:event_submitButton2ActionPerformed

    private void concessionCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_concessionCBItemStateChanged
        if(evt.getStateChange()==ItemEvent.SELECTED){
            // If the concession is checked enable the concession types
            studentRB.setEnabled(true);
            pdRB.setEnabled(true);
            seniorRB.setEnabled(true);
            
            if(studentRB.isSelected())
                userData.setConcessionType(UserData.STUDENT);
            else if(pdRB.isSelected())
                userData.setConcessionType(UserData.PHYSICALLY_DISABLED);
            else
                userData.setConcessionType(UserData.SENIOR_CITIZEN);
        } else{
            //If concession is unchecked disable the concession types
            studentRB.setEnabled(false);
            pdRB.setEnabled(false);
            seniorRB.setEnabled(false);
            
            userData.setConcessionType(UserData.NO_CONCESSION);
        }
    }//GEN-LAST:event_concessionCBItemStateChanged

    private void aboutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutButtonActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new busticketvendingsystem.AboutDialog(UserInputForm.this,true).setVisible(true);
            }
        });
    }//GEN-LAST:event_aboutButtonActionPerformed
    private void logIn(){
        char[] input=enterPasswordField.getPassword();
        if(isPasswordCorrect(input)){
            enterPasswordField.setText("");
            new busticketvendingsystem.AdministrativeTools(UserInputForm.this,true).setVisible(true);
            
        }
        else
            JOptionPane.showMessageDialog(UserInputForm.this,"Password is incorrect! try again.","WRONG PASSWORD",JOptionPane.ERROR_MESSAGE);
    }
    private boolean isPasswordCorrect(char[] input) {
    boolean isCorrect = true;
    String correctPassword = cd.getPassword();

    if (input.length != correctPassword.length()) {
        isCorrect = false;
    } else {
        for (int i = 0; i < input.length; i++) {
            if (input[i] != correctPassword.charAt(i)) {
                isCorrect = false;
            }
        }
    }

    //Zero out the password.
    correctPassword="";
    return isCorrect;
}
    private void setPassword(){
        char newpass[]=jPasswordField3.getPassword();
        String newpassword="";
        for(int i=0;i<newpass.length;i++)
            newpassword+=newpass[i];
        char repass[]=jPasswordField4.getPassword();
        char prepass[]=jPasswordField2.getPassword();
        if(isNewPasswordCorrect(newpass,repass)&&isPasswordCorrect(prepass)){
            jPasswordField3.setText("");
            jPasswordField4.setText("");
            jPasswordField2.setText("");
            cd.setPassword(newpassword);
            JOptionPane.showMessageDialog(UserInputForm.this,"Password has been changed!");
        }
        else{
            JOptionPane.showMessageDialog(UserInputForm.this,"Password is incorrect! try again.","WRONG PASSWORD",JOptionPane.ERROR_MESSAGE);
        }
    }
    private boolean isNewPasswordCorrect(char[] newpass,char[] repass){
        boolean isCorrect=true;
        if(newpass.length!=repass.length){
            isCorrect=false;
        }
        else{
            for (int i = 0; i < newpass.length; i++){
                if(newpass[i]!=repass[i]){
                    isCorrect=false;
                }
            }
        }
        return isCorrect;
    }
    private void countAmount(){
        float absdist=cd.getAbsoluteDistance((String)startingPointCB.getSelectedItem(),(String)destinationCB.getSelectedItem());
        String fare[]=cd.getFare();
        float minf=Float.parseFloat(fare[0]);
        float unitf=Float.parseFloat(fare[1]);
        float con=1;
        if(userData.getConcessionType()==0){
            con=1;
        }
        else if(userData.getConcessionType()==1){
            con=(float)2/3;
        }
        else if(userData.getConcessionType()==2){
            con=(float)1/3;
        }
        else{
            con=(float)1/2;
        }
        float amount=(absdist*unitf+minf)*userData.getNoTickets()*con;
        int rupee=(int)amount;
        float paisa=amount-rupee;
        if(paisa<=0.5&&paisa>0.0){
            paisa=1/2;
        }
        else if(paisa!=0.0){
            paisa=1;
        }
        amount=rupee+paisa;
        userData.setAmount(amount);
    }
    private int getAvailable_seats(String bnumber,String sname1,String sname2){
        int count=0;
        int stpid1=cd.getStoppage_id(sname1);
        int stpid2=cd.getStoppage_id(sname2);
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String date=dateFormat.format(new java.util.Date());
        userData.setDate(date);
        String tickets[]=cd.getTransaction_date_bnumberwise(date,bnumber);
        
        for(int i=0;i<tickets.length;i++){
            String sid1="",sid2="",dir="";
            int len=tickets[i].length();
            dir=tickets[i].substring(len-1,len);
            sid1=tickets[i].substring(len-4,len-1);
            sid2=tickets[i].substring(len-7,len-4);
            int id1=Integer.parseInt(sid1);
            int id2=Integer.parseInt(sid2);
            int direction=Integer.parseInt(dir);
            if(id1<id2){
                int tmp=id1;
                id1=id2;
                id2=tmp;
            }
            if((upRB.isSelected()&&direction==1)||(downRB.isSelected()&&direction==0)){
                for(int j=id1;j>id2;j--){
                    if(j==stpid1){
                        count++;
                    
                        break;
                    }
                    else if(j==stpid2){
                        count++;
                    
                        break;
                    }
                }
            }
        }
        int seat=cd.getSeats(bnumber)-count;
        return seat;
    }
    private String[] getScheduleTime(int dir){
        String schedule[]=new String [cd.getNumber_of_rows("Bus")];
        if(dir==1){
            schedule=cd.getUpSchedule();
        }
        else{
            schedule=cd.getDownSchedule();
        }
        SimpleDateFormat timeFormat=new SimpleDateFormat("HH");
        String hour=timeFormat.format(new java.util.Date());
        String sch[]=new String [cd.getNumber_of_rows("Bus")];
        int k=0;
        for(int i=0;i<schedule.length;i++){
            if(Integer.parseInt(schedule[i].substring(0,2))>=Integer.parseInt(hour)){
                sch[k]=schedule[i];
                k++;
            }
            
        }
        String puresch[] =new String [k];
        for(int i=0;i<k;i++)
            puresch[i]=sch[i];
        return puresch;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UserInputForm().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aboutButton;
    private javax.swing.JPanel administrativeUse;
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JLabel busNoLabel;
    private javax.swing.JTextField busNoTextField;
    private javax.swing.JCheckBox concessionCB;
    private javax.swing.JLabel concessionIllustration;
    private javax.swing.JPanel concessionPanel;
    private javax.swing.ButtonGroup concessionTypeButtonGroup;
    private javax.swing.JLabel dateTimeLabel;
    private javax.swing.JComboBox destinationCB;
    private javax.swing.JLabel destinationLabel;
    private javax.swing.JRadioButton downRB;
    private javax.swing.JPasswordField enterPasswordField;
    private javax.swing.JLabel enterPasswordLabel;
    private javax.swing.JLabel fillInLabel;
    private javax.swing.JPanel footerPanel;
    private javax.swing.JPanel headerPanel;
    private javax.swing.JButton helpButton;
    private javax.swing.JButton helpButton3;
    private javax.swing.JScrollPane informationPane;
    private javax.swing.JPanel inputFormPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton4;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField2;
    private javax.swing.JPasswordField jPasswordField3;
    private javax.swing.JPasswordField jPasswordField4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JScrollPane mainPane;
    private javax.swing.JButton mapButton;
    private javax.swing.JRadioButton monthlyRadioButton;
    private javax.swing.JLabel noOfSeatsLabel;
    private javax.swing.JTextField noOfSeatsTextField;
    private javax.swing.JPanel noTicketsPanel;
    private javax.swing.JSpinner noTicketsSpinner;
    private javax.swing.JRadioButton pdRB;
    private javax.swing.JRadioButton quarterlyRadioButton;
    private javax.swing.JRadioButton regularRadioButton;
    private javax.swing.JButton resetAllButton;
    private javax.swing.JButton save;
    private javax.swing.JPanel schedulePanel;
    private javax.swing.JComboBox scheduleTimeCB;
    private javax.swing.JLabel scheduleTimeLabel;
    private javax.swing.JRadioButton seniorRB;
    private javax.swing.JComboBox startingPointCB;
    private javax.swing.JLabel startingPointLabel;
    private javax.swing.JPanel stoppagePanel;
    private javax.swing.JRadioButton studentRB;
    private javax.swing.JButton submitButton2;
    private javax.swing.JTabbedPane tabbedPane;
    private javax.swing.JPanel ticketTransaction;
    private javax.swing.ButtonGroup ticketTypeButtonGroup;
    private javax.swing.JPanel ticketTypePanel;
    private javax.swing.JPanel topPanel;
    private javax.swing.ButtonGroup upDownButtonGroup;
    private javax.swing.JPanel upDownPanel;
    private javax.swing.JRadioButton upRB;
    private javax.swing.JRadioButton yearlyRadioButton;
    // End of variables declaration//GEN-END:variables
    
}
